From cd9f5733b3e354301f29f1526744fec2da6fdfc8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 26 Jun 2020 15:49:39 -0400 Subject: [PATCH] text: Be more selective when selecting on focus-in We don't want to select on focus-in when the focus comes from a child. The case where this does harm is when you activate copy or paste actions from the context menu. We close the menu before triggering the action, and if that causes the text in the entry to be selected, unexpected things happen, since the action applies to the current selection. Fixes: #2869 --- gtk/gtktext.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 67400607a9..ff6fde8e5b 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -3193,11 +3193,15 @@ gtk_text_grab_focus (GtkWidget *widget) GtkText *self = GTK_TEXT (widget); GtkTextPrivate *priv = gtk_text_get_instance_private (self); gboolean select_on_focus; + GtkWidget *prev_focus; + + prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget)); if (!GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self))) return FALSE; - if (priv->editable && !priv->in_click) + if (priv->editable && !priv->in_click && + !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget))) { g_object_get (gtk_widget_get_settings (widget), "gtk-entry-select-on-focus", -- 2.30.2